<?php
/*
 * @Author: 持禅 1791106511@qq.com
 * @Date: 2023-09-21 09:07:48
 * @LastEditors: 持禅 1791106511@qq.com
 * @LastEditTime: 2023-10-09 11:39:16
 * @FilePath: \fuls.top\app\admin\controller\Article.php
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

namespace app\admin\controller;

use think\facade\{View, Session, Db};
use app\BaseController;

class Article extends Base
{
    public function artlst(){
        if ($this->Ajax) {
            $page = input("page", 1);
            $size = input("limit", 100);
            $mp = [];
 
            if(strlen(input('status'))){
                $mp[]=["status","=",input('status')];
            }
            $mp[]=["type","=",input('type',0)];
            if(trim(input('title'))){
                $mp[]=["title","like","%".trim(input('title'))."%"];
            }
            $lst = Db::name("article")->where($mp)->order("or_w desc")->page($page, $size)->select()->toArray();
            foreach ($lst as &$v) {
                $v['addtime'] = date("Y-m-d H:i:s", $v['addtime']);
                $v['amsg']=Db::name("auser")->find($v['mid']);
               
            }
            $count = Db::name("article")->where($mp)->count();



            return resmsg(0, "检索成功", $lst, $count);
        }
        return View::fetch(); 
    }
    // 状态变更
    public function setStatus(){
        Db::name('article')->where("id",input("id"))->update([
            'uptime'=>time(),
            'status'=>input('status'),
            'upid'=>Session("lt_auser")['id'],
          
        ]);
        return returnmsg(200,"操作成功");
    }
    //删除记录
    public function itemDelete(){
        Db::name('article')->where("id",input("id"))->delete();
        return returnmsg(200,"操作成功");
    }
    //广告录入页面
    public function artedit(){
        
        $msg=Db::name("article")->find(input("id"));
        
        View::assign("msg",$msg);

        return View::fetch("article/src/artedit");
    }
    //广告更新
    public function artSave(){
        $param = input('param.', []);
            if(input('type')!=2){
        
            if($_FILES['img']['size']){
                // 头图 
                $file = request()->file('img');
                $param['img'] = uniqid() .".".$file->extension();
                \think\facade\Filesystem::disk('files')->putFileAs("runtimefile", $file,$param['img']);
            }else{
            
                    if(!input('id')){
                        return returnmsg(199,"请上传头图");
                    }
            
            }
        }

        if (!$param['id']) {
            unset($param['id']);
            $param['addtime'] = time();
            $param['mid']=Session("lt_auser")['id'];
  
            $param['type']=input("type",0);
       
        }
        $param['uptime']=time();
        $param['upid']=Session("lt_auser")['id'];

        $is = Db::name("article")->strict(false)->save($param);


        return $is ? returnmsg(200, "操作成功") : returnmsg(201, "操作失败");
    }


}